package com.huawei.esdk.tp.device.smc.convert;

import java.util.List;

import com.huawei.esdk.tp.southcommu.cxf.gen.ArrayOfStringSouth;
import com.huawei.esdk.tp.southcommu.cxf.gen.ConferenceIdSouth;
import com.huawei.esdk.tp.southcommu.cxf.gen.ConnectSitesSouth;
import com.huawei.esdk.tp.southcommu.cxf.gen.DisconnectSitesSouth;
import com.huawei.esdk.tp.southcommu.cxf.gen.MuteSitesSouth;
import com.huawei.esdk.tp.southcommu.cxf.gen.QuietSitesSouth;


public class TPSiteCtrConvert
{
    public static ConnectSitesSouth connectSitesParamConvert(String confID,
            List<String> sitesUri)
    {
        ConnectSitesSouth request = new ConnectSitesSouth();
        request.setConfId(conferenceIdRequestParamMap(confID));
        request.setSiteUris(arrayOfSiteUriRequestParamMap(sitesUri));
        return request;
    }

    public static DisconnectSitesSouth disconnectSitesParamConvert(String confID,
            List<String> sitesUri)
    {
        DisconnectSitesSouth request = new DisconnectSitesSouth();
        request.setConfId(conferenceIdRequestParamMap(confID));
        request.setSiteUris(arrayOfSiteUriRequestParamMap(sitesUri));
        return request;
    }
    
    public static MuteSitesSouth muteSitesParamConvert(String confID, List<String> sitesUri,
            boolean actionCode)
    {
        MuteSitesSouth request = new MuteSitesSouth();
        request.setConfId(conferenceIdRequestParamMap(confID));
        request.setSiteUris(arrayOfSiteUriRequestParamMap(sitesUri));
        request.setIsMute(actionCode);
        return request;
    }
    
    public static QuietSitesSouth quietSitesParamConvert(String confID, List<String> sitesUri,
            boolean actionCode)
    {
        QuietSitesSouth request = new QuietSitesSouth();
        request.setConfId(conferenceIdRequestParamMap(confID));
        request.setSiteUris(arrayOfSiteUriRequestParamMap(sitesUri));
        request.setIsQuiet(actionCode);
        return request;
    }
    
    private static ConferenceIdSouth conferenceIdRequestParamMap(String confID) {
        ConferenceIdSouth conferenceID = new ConferenceIdSouth();
        try {
            conferenceID.setConfInternalId(Long.valueOf(confID));
        } catch (NumberFormatException e) {
            return null;
        }
        return conferenceID;
    }

    private static ArrayOfStringSouth arrayOfSiteUriRequestParamMap(
            List<String> SiteUris) {
        ArrayOfStringSouth arrayOfStringSouth = new ArrayOfStringSouth();
        for (String siteUri : SiteUris) {
            if (!arrayOfStringSouth.getString().add(siteUri))
                break;
        }
        return arrayOfStringSouth;
    }
}
